package com.three.lab.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.three.lab.R;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

public class SameItemImageAdapter extends RecyclerView.Adapter<SameItemImageAdapter.ViewHolder> {
    private Context mActivity;
    private List<String> list;
    public SameItemImageAdapter(Context activity, List<String> list) {
        this.mActivity = activity;
        this.list = list;
    }
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        ViewHolder holder = new ViewHolder(LayoutInflater.from(mActivity).inflate(R.layout.item_list_avatar, viewGroup, false));
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) {
        Glide.with(mActivity).load(list.get(i)).placeholder(R.mipmap.ic_avatar_52).diskCacheStrategy(DiskCacheStrategy.ALL).skipMemoryCache(false).into(viewHolder.mLikehead);
        if(i==0){
            setMargins(viewHolder.mRelayout,0,0,0,0);
        }

    }
    public void setMargins (View v, int l, int t, int r, int b) {
        if (v.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
            ViewGroup.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
            p.setMargins(l, t, r, b);
            v.requestLayout();
        }
    }
    @Override
    public int getItemCount() {
        if (list == null) {
            return 0;
        }
        return list.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        private final CircleImageView mLikehead;
        private final RelativeLayout mRelayout;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            mRelayout = itemView.findViewById(R.id.relayout);
            mLikehead = itemView.findViewById(R.id.iv_avatar);
        }
    }
}

